
*Creates Figure B.8a.  The shapefile comes from the 2015-16 school attendance boundary survey (primary schools shapefile) available here: https://nces.ed.gov/programs/edge/sabs.

clear all
set more off
ssc install geocircles

cd "C:\Users\gilraine\OneDrive\Desktop\Old Laptop\LA Air Filters\JHR Data Repository\Air Testing Data and Code\School Zones\"

shp2dta using "primary_lat_lon", database("attendance_boundaries.dta") coordinates("boundary_coord.dta") genid(id) 

*Create Circle:
clear all
geocircles 34.315467 -118.563731 5.0, database("circle.dta") coordinates("circle_coord.dta") miles  

clear all
use "circle.dta"
ren _ID id
save "circle.dta", replace

clear all
use "boundary_coord.dta"
drop if _ID==1
save "boundary_coord.dta", replace

clear all
use "attendance_boundaries.dta"
drop if id==1
append using "circle.dta"

*LAUSD is id 0622710
su id if leaid=="0622710"
*So it is LAUSD if if id>=4341 & id<=4848 (4849 is that weird island off of LA)

*Last five digits are school id
gen necs_school=substr(ncessch,-5,.)

keep if (id>=4341 & id<=4848) | id==1

*School codes for RD schools
gen RD_sample=.
gen treated=0
replace RD_sample=1 if necs_school=="02842"
replace RD_sample=1 if necs_school=="03419"
replace RD_sample=1 if necs_school=="02979"
replace RD_sample=1 if necs_school=="02949"
replace RD_sample=1 if necs_school=="03041"

replace RD_sample=1 if necs_school=="03119"
replace RD_sample=1 if necs_school=="03049"
replace RD_sample=1 if necs_school=="02915"
replace RD_sample=1 if necs_school=="03381"
replace RD_sample=1 if necs_school=="03402"

replace RD_sample=1 if necs_school=="02814"

***Below this is treated, rest `control'***
replace treated=1 if RD_sample==1

replace RD_sample=1 if necs_school=="03406"
replace RD_sample=1 if necs_school=="02885"
replace RD_sample=1 if necs_school=="03080"
replace RD_sample=1 if necs_school=="02978"
replace RD_sample=1 if necs_school=="03174"

*One below is balboa, which is a magnet elementary and so does not have an attendance zone
replace RD_sample=1 if necs_school=="02833"
replace RD_sample=1 if necs_school=="02948"
replace RD_sample=1 if necs_school=="03074"
replace RD_sample=1 if necs_school=="02951"
replace RD_sample=1 if necs_school=="03208"

replace RD_sample=1 if necs_school=="03138"
replace RD_sample=1 if necs_school=="03254"
replace RD_sample=1 if necs_school=="13198"
replace RD_sample=1 if necs_school=="03438"
replace RD_sample=1 if necs_school=="03469"

replace RD_sample=1 if necs_school=="03384"
replace RD_sample=1 if necs_school=="02968"

replace RD_sample=1 if id==1

spmap treated using "boundary_coord.dta" if RD_sample==1, id(id) polygon(data("circle_coord.dta") osize(thick)) fcolor(BuGn)

*Coverage percents*
gen point_lat=34.315467
gen point_lon=-118.563731

*Figure B.8a
spmap treated using "boundary_coord.dta" if RD_sample==1, id(id) point(xcoord(point_lon) ycoord(point_lat)) polygon(data("circle_coord.dta") osize(thick)) fcolor("255 204 203" green)


erase "attendance_boundaries.dta"
erase "boundary_coord.dta"
erase "circle_coord.dta"
erase "circle.dta"




